package testenv.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;
import org.springmole.business.bean.QueryRequest;


@Controller
public class HomeController {
	

	@RequestMapping(value="/home.do", method=RequestMethod.GET)
	public ModelMap processGet(ModelMap modelMap) {
		
		QueryRequest queryRequest = new QueryRequest(
				"jdbc:postgresql://localhost/migrate",
				"postgres",
				"postgres",
				"Select * from product;",
				"id",
				"asc",
				0,
				10);
		
		modelMap.addAttribute("queryRequest", queryRequest);
		
		return modelMap;
	}
	
	
	@RequestMapping(method=RequestMethod.POST)
	public String processQueryPost(
			@ModelAttribute("queryRequest") QueryRequest queryRequest,
			BindingResult result,
			SessionStatus status,
			ModelMap modelMap) {
		
		return "forward:database.spy";
	}
	
}
